import { GlobalApi } from '../api/GlobalApi'
import { ResponseType } from '../api/responseType'

/**
 * 动态点赞
 * @param dynamicInfo
 */
export async function fetchThumbsUp(dynamicInfo: ResponseType.DynamicInfo) {
  const { dynamicId, liked } = dynamicInfo
  const params = {
    dynamicId,
    flag: liked ? 0 : 1
  }
  await GlobalApi.thumbsUp(params)
  dynamicInfo.liked = !liked
  dynamicInfo.likeCount += !liked ? 1 : -1
}

/**
 * 评论点赞
 * @param commentInfo
 */
export async function fetchCommentThumbsUp(commentInfo: ResponseType.CommentInfo) {
  const { commentId, liked } = commentInfo
  const params = {
    commentId,
    flag: liked ? 0 : 1
  }
  await GlobalApi.commentThumbsUp(params)
  commentInfo.liked = !liked
  commentInfo.likeCount += !liked ? 1 : -1
}

/**
 * 回复评论点赞
 * @param replyInfo
 */
export async function fetchReplyThumbsUp(replyInfo: ResponseType.ReplyInfo) {
  const { replyId, liked } = replyInfo
  const params = {
    replyId,
    flag: liked ? 0 : 1
  }
  await GlobalApi.replyThumbsUp(params)
  replyInfo.liked = !liked
  replyInfo.likeCount += !liked ? 1 : -1
}
